// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;
import ZhuanBlock from "./ZhuanBlock";
@ccclass
export default class ZhuanMain extends cc.Component {

    @property(cc.Layout)
    itemLayout: cc.Layout = null

    @property(cc.Prefab)
    block: cc.Prefab = null

    // LIFE-CYCLE CALLBACKS:
    row = 15;

    column = 12;

    // onLoad () {}
    blocks = []
    start () {
        window.MainGame = this;
        this.initBlocks()
    }
    initBlocks() {
        this.itemLayout.enabled = true;
        // 节点数量自定义
        for(let i = 0;  i < this.row; i++){
            let blockArr = []
            for(let j = 0;  j < this.column; j++){
                let block = cc.instantiate(this.block)
                block.getComponent(ZhuanBlock).init(i, j)
                block.parent = this.itemLayout.node
                blockArr.push(block)
            }
            this.blocks.push(blockArr)
        }
        this.itemLayout.updateLayout()
        this.itemLayout.enabled = false; // 关闭布局，否则会闪烁
    }

    // update (dt) {}
}
